package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.mapper.SetMealDishMapper;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetMealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

@RestController("管理端userSetmeal")
@RequestMapping("/admin/setmeal")
@Api(tags = "设置套餐接口")
@Slf4j
public class SetMealController {
    @Autowired
    public SetMealService setMealService;
    @Autowired
    private SetMealDishMapper setMealDishMapper;

    /**
     * 套餐分页查询
     *
     * @param setmealPageQueryDTO
     * @return
     */
    @ApiOperation(value = "套餐分页查询")
    @GetMapping("/page")
    public Result<PageResult> page(SetmealPageQueryDTO setmealPageQueryDTO){
        PageResult pageResult = setMealService.pageQuery(setmealPageQueryDTO);//后续定义
        return Result.success(pageResult);
    }

    /**
     *新增套餐
     *
     * @param setmealDTO
     * @return
     */
    @ApiOperation(value = "新增套餐")
    @PostMapping
    @CacheEvict(cacheNames = "setmealCache",allEntries = true)
    public Result<String> add(@RequestBody SetmealDTO setmealDTO){
        log.info("新增分类信息: {}", setmealDTO);
        setMealService.addSetmeal(setmealDTO);
        return Result.success();
    }

    /**
     * 起售停售套餐
     *
     * @param status
     * @param id
     * @return
     */
    @ApiOperation("起售停售套餐")
    @PostMapping("/status/{status}")
    @CacheEvict(cacheNames = "setmealCache",allEntries = true)
    public Result<Object> startOrStop(@PathVariable Integer status, long id){
        log.info("起售停售分类id: {}", id);
        setMealService.startOrStop(status, id);
        return Result.success();
    }

    /**
     * 修改套餐信息
     *
     * @param setmealVO
     * @return
     */
    @ApiOperation("修改套餐信息")
    @PutMapping
    @CacheEvict(cacheNames = "setmealCache",allEntries = true)
    public Result<Object> editEmployeeMessage(@RequestBody SetmealVO setmealVO){
        log.info("修改分类信息: {}", setmealVO);
        setMealService.edit(setmealVO);
        return Result.success();
    }

    /**
     * 删除套餐
     *
     * @param ids
     * @return
     */
    @ApiOperation("删除套餐")
    @DeleteMapping
    @CacheEvict(cacheNames = "setmealCache",allEntries = true)
    public Result<Object> deleteCategory(long[] ids){
        setMealService.deleteById(ids);
        return Result.success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id回显菜品信息")
    public Result<SetmealVO> getByID(@PathVariable long id){
        SetmealVO setmealVO = setMealService.getById(id);
        return Result.success(setmealVO);
    }
}
